<template>
	<view :style="{'padding-top':mt+'px'}">
		<c-nav-bar :title="titleOrder"></c-nav-bar>
		<view class="date">
			{{getDate()}}
		</view>
		<view class="collapse">
			<view class="" v-for="(item,index) in collapseList" :key="index">
				<view class="collapseTitle" @click="open(index)">
					<span>{{item.tagName}}</span>
					<span style="color: #a2a2a2;" v-if='openIndex==index'><u-icon name="arrow-up"></u-icon></span>
					<span style="color: #a2a2a2;" v-else><u-icon name="arrow-down"></u-icon></span>
				</view>
				<view class="collapseItem" v-show='openIndex==index'>
					<view class="title">
						<text>航班次</text>
						<text>开船时间</text>
						<text>上船码头</text>
						<text>船名</text>
						<text>状态</text>
					</view>
					<view class="content" v-for="(i,idx) in shipInfo" :key="idx">
						<text>{{i.lineNum+''+i.sx}}次</text>
						<text>{{i.sailTime}}</text>
						<text>{{i.startPortName}}</text>
						<text>{{i.shipName}}</text>
						<text style='color: #007A69;width:90rpx'>
							<text style="font-size: 24rpx;" @click="goToShipMap(i,idx)">卫星图</text>
						</text>
					</view>
					<view class="tip">
						<text style="color: darkorange;">提示：</text>
						<text style="color: #c5c5c5;">泗礁往返沈家湾航程：高速客船约1小时；常规客船约1小时30分钟；豪华游轮约1小时30分钟；车客渡约1小时50分钟</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				titleOrder: '船舶位置',
				collapseList: [],
				shipInfo: [],
				gangkoudata: {},
				openIndex: null
			}
		},
		onLoad() {
			this.insertFlag()
			this.getPortLineList()
		},
		methods: {
			getDate() {
				const currentDate = new Date();
				const year = currentDate.getFullYear();
				const month = String(currentDate.getMonth() + 1).padStart(2, '0');
				const day = String(currentDate.getDate()).padStart(2, '0');
				const weekday = ['日', '一', '二', '三', '四', '五', '六'][currentDate.getDay()];

				const formattedDate = `${year}-${month}-${day} 周${weekday}`;
				return formattedDate
			},
			geFlightList(item) {
				const params = {
					endPortNo: item.endPortNum,
					startPortNo: item.startPortNum
				}
				this.$api.post('/api/apishiprealtimeposition/flightList', params).then(res => {
					if (res.data.code == 0) {
						this.shipInfo = res.data.data
						console.log(res, '11111');
					}
				})
			},
			getPortLineList() {
				this.$api.get('/api/apishiprealtimeposition/portLineList', {
					params: {}
				}).then(res => {
					if (res.data.code == 0) {
						this.collapseList = res.data.data
					}
					console.log(res, 'res+++++++++++');
				})
			},
			goToShipMap(item, index) {
				//console.log(item,index);
				let postdata = {
					index: index,
					endPortNum: this.gangkoudata.endPortNum,
					startPortNum: this.gangkoudata.startPortNum,
				};
				console.log('111111111111111111', postdata)

				//  console.log('postdata',postdata)
				uni.navigateTo({
					url: '/pages/touristMap/Satelliteimage?shipInfo=' + JSON.stringify(postdata)
				})
			},
			open(index) {
				this.openIndex = index
				const item = this.collapseList[index];
				this.gangkoudata = this.collapseList[index]
				console.log('this.gangkoudata', this.gangkoudata)
				this.geFlightList(item)
			},
			close(e) {
				// console.log('close', e)
			},
			change(e) {
				//console.log('change', e)
			},
			insertFlag() {
				for (let i = 0; i < this.collapseList.length; i++) {
					if (i == 0) {
						this.collapseList.flag = 0
					} else {
						if (this.collapseList[i].begin !== this.collapseList[i - 1].begin) {
							this.collapseList.flag = 1
						} else {
							this.collapseList.flag = 0
						}
					}

				}
			}
		},

	}
</script>

<style lang="scss">
	.u-page {
		padding: 0;

		&__item {

			&__title {
				color: $u-tips-color;
				background-color: $u-bg-color;
				padding: 15px;
				font-size: 15px;

				&__slot-title {
					color: $u-primary;
					font-size: 14px;
				}
			}
		}
	}

	.u-collapse-content {
		color: $u-tips-color;
		font-size: 14px;
	}

	.date {
		width: 100%;
		height: 87rpx;
		background: #007A69;
		color: #fff;
		text-align: center;
		line-height: 87rpx;
		font-size: 30rpx;
	}

	.collapse {
		.collapseTitle {
			display: flex;
			flex-direction: row;
			box-sizing: border-box;
			padding: 14px 15px;
			font-size: 15px;
			color: #303133;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #efefef;

		}

		.collapseItem {
			.title {
				background: #007A69;
				display: flex;
				justify-content: space-between;
				padding: 0px 45rpx 0 29rpx;
				color: #fff;
				height: 60rpx;
				align-items: center;
			}

			.content {
				align-items: center;
				height: 120rpx;
				border-bottom: 1rpx dashed #c5c5c5;
				display: flex;
				justify-content: space-between;
				padding: 0 20rpx;
			}

			.tip {
				padding: 10rpx;
			}
		}


		.content1 {
			align-items: center;
			height: 120rpx;
			display: flex;
			justify-content: space-between;
			padding: 0 10rpx;

			.timeShip {
				display: flex;
				flex-direction: row;
				width: 100rpx;
				justify-content: space-between;
				align-items: center;
			}

			.node {
				display: block;
				width: 20rpx;
				height: 20rpx;
				border-radius: 20rpx;
				background: #b4b4b4;
				position: relative;

				.vertical {
					border-left: 1rpx solid #c5c5c5;
					height: 110rpx;
					display: block;
					position: absolute;
					top: 18rpx;
					left: 8rpx;
				}
			}
		}


	}

	::v-deep .u-collapse-item__content__text {
		padding: 0 !important;
	}
</style>